<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
	<title>引入正则表达式</title>
	<style type="text/css">
	* {
		padding: 0;
		margin: 0;
	}
    </style>
</head>
<body>
	<div class="container">
		<h1>引入正则表达式</h1>
	</div>
	<script src="https://cdn.staticfile.org/jquery/3.2.0/jquery.js"></script>
	<script type="text/javascript">
	// 提取连续的多个数字
	var str='hello12 fff 87 er334 233 -=-=fa80你好';

	function findNums2(str) {
		var arr=[];
		var tmp='';
		for(var i=0;i<str.length;i++)
		{
			if(str.charAt(i)>='0' && str.charAt(i)<='9')
			{
				tmp += str.charAt(i);
			}
			else
			{
				if(tmp)
				{
					arr.push(tmp);
					tmp ='';
				}
			}
		}
		if(tmp)
		{
			arr.push(tmp);
			tmp='';
		}

		return arr
	}

	/**
	 * 提取连续的数字
	 * @param  {[type]} str [description]
	 * @return {[type]}     [description]
	 */
	function findNums(str) {
		var one, tmp = [], numsArr = []
		for (var i = 0, len = str.length; i < len; i++) {
			one = str[i]

			if(one >= '0' && one <= '9') {
				tmp.push(one)
			} else {
				if(tmp.length) {
					numsArr.push(tmp.join(''))
					tmp = []
				}
			}
		}

		if(tmp.length) {
			numsArr.push(tmp.join(''))
			tmp = []
		}

		return numsArr
	}
	// 传统编码进行字符串查询示例
	console.log(findNums(str))
	console.log(findNums2(str))


	// 正则表达式示例
	var reg = /\d+/g
	console.log(str.match(reg))
	
	</script>
</body>
</html>